package com.corechina.apex_osswords.domain.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.corechina.apex_osswords.domain.entity.CoreWorkOrder;
import com.corechina.apex_osswords.domain.vo.CoreWorkOrderVo;
import com.corechina.apex_osswords.domain.vo.ProjectStatistics;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * <p>
 * 工单表 Mapper 接口
 * </p>
 *
 * @author cc
 * @since 2022-03-11
 */
@Component
public interface CoreWorkOrderMapper extends BaseMapper<CoreWorkOrder> {

    int updateByPrimaryKey(CoreWorkOrder coreWorkOrder);

    int updateByWeiXin(CoreWorkOrder coreWorkOrder);

    IPage<CoreWorkOrderVo> getList(Page page, @Param("equipmentId") Integer equipmentId, @Param("sortType") Integer sortType, @Param("beginDate") String beginDate, @Param("endDate") String endDate, @Param("warningDay") Integer warningDay, @Param("projectName") String projectName, @Param("state") String state, @Param("disposeResult") Integer disposeResult, @Param("createUserType") Integer createUserType, @Param("recipientName") String recipientName, @Param("enterpriseId") Integer enterpriseId);

    CoreWorkOrderVo getOne(@Param("id") Integer id);

    IPage<CoreWorkOrderVo> getListForWeiXin(Page page, @Param("userId") Integer userId, @Param("state") String state, @Param("disposeResult") Integer disposeResult, @Param("userType") Integer userType, @Param("sortType") Integer sortType, @Param("enterpriseId") Integer enterpriseId);

    int disposeOrder(CoreWorkOrder coreWorkOrder);

    ProjectStatistics getOrderCount(@Param("userId") Integer userId, @Param("state") Integer state, @Param("enterpriseId") Integer enterpriseId);

    int updateRecipient(@Param("failureDescription") String failureDescription, @Param("remark") String remark, @Param("repairId") Integer repairId, @Param("recipient") Integer recipient, @Param("planTime") Date planTime, @Param("state") Integer state, @Param("id") Integer id);

    @Update("update core_work_order set state = #{state} where id = #{id}")
    int updateOrderState(@Param("state") Integer state, @Param("id") Integer id);

    @Select("select count(1) from core_work_order where equipment_id = #{equipmentId}")
    int checkEquipment(@Param("equipmentId") Integer equipmentId);

    int auditOder(CoreWorkOrder coreWorkOrder);
}
